package com.zj.leetcode.easy.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: algorithm
 * @description: 二叉树的中序遍历
 * 94 binary-tree-inorder-traversal
 * @author: Zhang Bo
 * @create: 2022-07-04 15:06:48
 **/
public class BinaryTreeInorderTraversal {
    public static void main(String[] args) {
        Solution solution = new BinaryTreeInorderTraversal().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    class Solution {
        List<Integer> list = new ArrayList<>();

        public List<Integer> inorderTraversal(TreeNode root) {
            if (root == null) {
                return list;
            }
            this.dfs(root);
            return list;
        }

        public void dfs(TreeNode node) {
            if (node != null) {
                if (node.left != null) {
                    this.dfs(node.left);
                }
                list.add(node.val);

                if (node.right != null) {
                    this.dfs(node.right);
                }
            }
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}